package com.sunyard.client2.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.sunyard.client.SunEcmClientApi;
import com.sunyard.client.bean.ClientBatchBean;
import com.sunyard.client.bean.ClientFileBean;
import com.sunyard.client2.ConnectionFactory;
import com.sunyard.client2.conf.ConfUtil;
import com.sunyard.util.OptionKey;

public class UpdateAttr extends JPanel {
	private JTextField textField1;
	private JTextField textField11;

	/**
	 * Create the panel.
	 */
	public UpdateAttr() {
		setLayout(null);

		JLabel label = new JLabel("属性:");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setBounds(99, 117, 54, 15);
		add(label);

		textField1 = new JTextField();
		textField1.setText("");
		textField1.setColumns(10);
		textField1.setBounds(195, 114, 178, 21);
		add(textField1);

		textField11 = new JTextField();
		textField11.setColumns(10);
		textField11.setBounds(408, 114, 178, 21);
		add(textField11);

		textField1.setText(ConfUtil.getString("userFileAttr1", ""));

		JButton btnNewButton = new JButton("修改");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				ClientFileBean fileBean1 = new ClientFileBean();
				fileBean1.setOptionType(OptionKey.U_MODIFY);
				fileBean1.setFileNO(textField.getText());
				fileBean1.addOtherAtt(textField1.getText(), textField11.getText());
				
				ClientBatchBean bean = batchInfoPanel.getBatchBean();
				bean.getDocument_Objects().get(0).addFile(fileBean1);
				try {
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					String resultMsg = clientApi.update(bean, ConfUtil.getString("groupName", ""), true);
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}

			}
		});
		btnNewButton.setBounds(320, 222, 93, 23);
		add(btnNewButton);
		
		lblNewLabel = new JLabel("文件：");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(99, 63, 54, 15);
		add(lblNewLabel);
		
		textField = new JTextField();
		textField.setBounds(195, 60, 391, 21);
		add(textField);
		textField.setColumns(10);

	}

	private UpdateBatchInfo batchInfoPanel;
	private JLabel lblNewLabel;
	private JTextField textField;

	public UpdateAttr(UpdateBatchInfo batchInfoPanel) {
		this();
		this.batchInfoPanel = batchInfoPanel;
	}
}
